package com.ruoyi.schedule.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.schedule.domain.DoctorSchedule;
import com.ruoyi.schedule.service.IDoctorScheduleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 医生排班Controller
 * 
 * @author ruoyi
 * @date 2023-09-04
 */
@RestController
@RequestMapping("/schedule/schedule")
public class DoctorScheduleController extends BaseController
{
    @Autowired
    private IDoctorScheduleService doctorScheduleService;

    /**
     * 查询医生排班列表
     */
//    @PreAuthorize("@ss.hasPermi('schedule:schedule:list')")
    @GetMapping("/list")
    public TableDataInfo list(DoctorSchedule doctorSchedule)
    {
        startPage();
        List<DoctorSchedule> list = doctorScheduleService.selectDoctorScheduleList(doctorSchedule);
        return getDataTable(list);
    }

    /**
     * 导出医生排班列表
     */
    @PreAuthorize("@ss.hasPermi('schedule:schedule:export')")
    @Log(title = "医生排班", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DoctorSchedule doctorSchedule)
    {
        List<DoctorSchedule> list = doctorScheduleService.selectDoctorScheduleList(doctorSchedule);
        ExcelUtil<DoctorSchedule> util = new ExcelUtil<DoctorSchedule>(DoctorSchedule.class);
        util.exportExcel(response, list, "医生排班数据");
    }

    /**
     * 获取医生排班详细信息
     */
//    @PreAuthorize("@ss.hasPermi('schedule:schedule:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(doctorScheduleService.selectDoctorScheduleById(id));
    }

    /**
     * 新增医生排班
     */
    @PreAuthorize("@ss.hasPermi('schedule:schedule:add')")
    @Log(title = "医生排班", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DoctorSchedule doctorSchedule)
    {
        return toAjax(doctorScheduleService.insertDoctorSchedule(doctorSchedule));
    }

    /**
     * 修改医生排班
     */
    @PreAuthorize("@ss.hasPermi('schedule:schedule:edit')")
    @Log(title = "医生排班", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DoctorSchedule doctorSchedule)
    {
        return toAjax(doctorScheduleService.updateDoctorSchedule(doctorSchedule));
    }

    /**
     * 删除医生排班
     */
    @PreAuthorize("@ss.hasPermi('schedule:schedule:remove')")
    @Log(title = "医生排班", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(doctorScheduleService.deleteDoctorScheduleByIds(ids));
    }
}
